#include "gtray.h"
#include <QDebug>
#include <glib.h>
#include <libappindicator/app-indicator.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>


static GMainLoop * mainloop = NULL;
AppIndicator *g_indicator = NULL;

void callback(){
    qDebug()<<"右键菜单  动态切换图标";
    app_indicator_set_icon(g_indicator, "evolution");  //设置托盘图标
}

void callbackmain(){
    qDebug()<<"主界面";
}

int main(int argc, char *argv[])
{
    gtk_init(&argc, &argv);

    //设置右键菜选项
    GtkWidget *main_Widget = gtk_menu_item_new_with_label("main");
    GtkWidget *menu_item   = gtk_menu_item_new_with_label("menu");
    GtkMenu *menu = GTK_MENU(gtk_menu_new());
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), main_Widget);
    gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
    gtk_widget_show(main_Widget);
    gtk_widget_show(menu_item);

    //注册托盘图标
    AppIndicator * indicator = app_indicator_new("test-application", "test",
                                          APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
    g_indicator = indicator;
    app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE); //设置图标状态
    app_indicator_set_menu(indicator, menu);
    app_indicator_set_title (indicator, _("test-tooltip"));

    //绑定 左键点击
    app_indicator_set_activate_target (indicator, main_Widget);
    g_signal_connect(G_OBJECT(main_Widget),"activate",G_CALLBACK(callbackmain),NULL);
    //绑定 右键或者中键 点击
    app_indicator_set_secondary_activate_target(indicator,menu_item);
    g_signal_connect(G_OBJECT(menu_item),"activate",G_CALLBACK(callback),NULL);


    mainloop = g_main_loop_new(NULL, FALSE);
    g_main_loop_run(mainloop);

    g_object_unref(G_OBJECT(indicator));
    g_object_unref(G_OBJECT(menu));
    g_object_unref(G_OBJECT(menu_item));

    return 0;
}


